package com.zhiyou100.video.webaction.speaker;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.opensymphony.xwork2.Preparable;
import com.zhiyou100.video.model.Course;
import com.zhiyou100.video.model.ResultMessage;
import com.zhiyou100.video.model.Speaker;
import com.zhiyou100.video.model.Subject;
import com.zhiyou100.video.model.Video;
import com.zhiyou100.video.service.SpeakerService;
import com.zhiyou100.video.utils.Page;
@SuppressWarnings("all")
@Controller("SpeakerAction")
@Scope(scopeName="prototype")
public class SpeakerAction extends ActionSupport implements ModelDriven<Speaker>{
	@Autowired
	SpeakerService ss;
	private Speaker speaker = new Speaker();
	@Override
	public Speaker getModel() {
		return speaker;
	}
	private String job;
	private String name;
	private Integer page;
	
	public String getJob() {
		return job;
	}

	public void setJob(String job) {
		this.job = job;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Integer getPage() {
		return page;
	}

	public void setPage(Integer page) {
		this.page = page;
	}

	public String speakerlist() throws Exception {
		job = job == null ? "": job;
		name = name == null ? "" : name;
		Integer currentpage= page == null ? 1 :page;
		DetachedCriteria dc = DetachedCriteria.forClass(Speaker.class);
		dc.add(Restrictions.ilike("speakerName", name, MatchMode.ANYWHERE)).add(Restrictions.ilike("speakerJob", job, MatchMode.ANYWHERE));
		Page<Speaker> slist=ss.selectSpeaker(dc,currentpage);
		ActionContext.getContext().put("pagep", slist);
		return SUCCESS;
	}
	
	public String speakeradd() throws Exception {
		
		return "speakeradd";
	}
	public String addspeaker() throws Exception {
		ss.addSpeaker(speaker);
		return "speakerlist";
	}
	public String speakermanage() throws Exception {
		Speaker slist = ss.selectSpeakerManage(speaker.getId());
		ActionContext.getContext().put("list", slist);
		return "speakermanage";
	}
	
}
